var path = require('path');
var fs = require('fs');
module.exports = function (UC, source, config, ArFor, cache, package) {
    var UserControl = UC;


    var RemoveFile = function (id, callback) {
        var Removedb = function () {
            new source("M_735", {
                id: id
                
            }, function (db) {
                callback();
            })
        };
        var _Remove = function () {
            new source("M_622", {
                id: id,
                
            }, function (db) {
                if (db && db.src) {
                    var src = db.src;
                    var _path = path.join(config.Files.FileCache, src);
                    fs.exists(_path, function (err) {
                        if (!err) {
                            Removedb();
                        } else {
                            fs.unlinkSync(_path);
                            Removedb();
                        }
                    })
                } else {
                    callback();
                }
            })
        };
        _Remove();
    }

    config.setParamet("RemoveFile", RemoveFile);
    var router = function (req, res, next) {

        var value = {
            error: 1
        };


        var query = req.query;
        config.RemoveFile(query.id, function () {

            res.Json(value)

        });


    }
    return router;



}